package com.dk.controller;

import com.dk.RES;
import com.dk.service.JwzxService;
import com.dk.service.UserService;
import com.jack.weChatSecurity.core.SecurityHelper;
import com.jack.weChatSecurity.core.WeChatUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api")
public class JwzxController {

    @Autowired
    UserService userService;
    @Autowired
    JwzxService jwzxService;

    @GetMapping("/week")
    @ResponseBody
    public RES getWeek(){
        RES res=new RES();
        try{
            int week= jwzxService.getWeek();
            res.setCode(0).setMsg("ok")
                    .addData("week",week);
        }catch (Exception e){
            e.printStackTrace();
            res.setCode(1).setMsg("error");
        }finally {
            return res;
        }
    }

    @GetMapping("/subject")
    @ResponseBody
    public RES getSubject(){
        RES res=new RES();
        try{
            WeChatUser weChatUser = SecurityHelper.getWeChatUser();
            String stuId=weChatUser.getAttribute("stuId");
            String subjects= jwzxService.getSubjects(stuId);
            res.setCode(0)
                    .setMsg("ok")
                    .addData("subjects",subjects);
        }catch (Exception e){
            e.printStackTrace();
            res.setCode(1).setMsg("error");
        }
        return res;
    }
}
